package astra.client.pages.employee;

import astra.client.Astra;
import astra.client.models.Client;
import astra.client.models.Employee;
import astra.client.pages.Page;
import astra.client.services.Filter;
import astra.client.utils.widgets.table.AdvancedTable;
import astra.client.utils.widgets.table.TableColumn;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiConstructor;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.IsSerializable;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.view.client.ListDataProvider;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Kotelnikov Dmitry <a href="mailto:dimonnot@mail.ru"/>
 */
public class EmployeePage extends Page {
    interface EmployeePageUiBinder extends UiBinder<HTMLPanel, EmployeePage> {
    }

    private static EmployeePageUiBinder ourUiBinder = GWT.create(EmployeePageUiBinder.class);

    @UiField(provided = true)
    CellTable table;
    @UiField
    Button showAddDialog;
    @UiField
    FlowPanel actions;

    private ListDataProvider<Employee> dataProvider;

    @UiConstructor
    public EmployeePage(String name) {
        super(name);

        table = new CellTable<Employee>();

        table.addColumn(
            new TextColumn<Employee>() {
                @Override
                public String getValue(Employee object) {
                    return object.getName();
                }
            },
            "ФИО"
        );
        table.addColumn(
            new TextColumn<Employee>(){
                @Override
                public String getValue(Employee object) {
                    return "изменить";
                }

                @Override
                public void onBrowserEvent(Cell.Context context, Element elem, Employee object, NativeEvent event) {
                    Window.alert(event.getType());
                }
            },
            ""
        );

        dataProvider = new ListDataProvider<Employee>();
        dataProvider.addDataDisplay(table);

        initWidget(ourUiBinder.createAndBindUi(this));
    }

    @Override
    public void show() {
        showActions(actions);
        dataProvider.setList(astra.getAstraData().getEmployees());
    }
}